<template>
  <div>
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="getList(1)"
      @clear="clear"
    />
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table"
    >
      <el-table-column
        align="center"
        :label="$t('message.ttmc')"
        min-width="200"
        prop="teamName"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="$t('message.gly')"
        show-overflow-tooltip
        min-width="200"
        prop="admin"
      />
      <el-table-column
        align="center"
        :label="$t('message.qylx')"
        prop="type"
        min-width="100"
      >
        <template slot-scope="scope">
          {{
            scope.row.type == "1"
              ? $t('message.shouchon')
              : scope.row.type == "2"
                ? $t('message.qianyue')
                : $t('message.qianyue')
          }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="$t('message.hyklx')"
        prop="cardType"
        show-overflow-tooltip
        min-width="200"
      />
      <el-table-column
        align="center"
        :label="$t('message.qyje')"
        prop="amot"
        show-overflow-tooltip
        min-width="100"
      />
      <el-table-column
        align="center"
        :label="$t('message.jyzt')"
        prop="status"
        min-width="100"
      >
        <template slot-scope="scope">
          {{
            scope.row.status == "0"
              ? $t('message.dzf')
              : scope.row.status == "1"
                ? $t('message.zc')
                : scope.row.status == "2"
                  ? $t('message.chexiao')
                  : $t('message.chexiao')
          }}
        </template>
      </el-table-column>
      <el-table-column align="center" :label="$t('message.heton')" prop="payTime" min-width="120">
        <template slot-scope="scope">
          <span
            class="primaryColor pointer"
            @click="downLoadHt(scope.row.htURL)"
          >{{ $t('message.djxz') }}</span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="$t('message.qysj')"
        prop="createDate"
        min-width="160"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="$t('message.czr')"
        prop="creator"
        min-width="120"
        show-overflow-tooltip
      />
    </el-table>
    <Paginations
      :total="totalCount"
      :page="pagination.page"
      @current-change="getList"
      @SizeChange="handleSizeChange"
    />
  </div>
</template>

<script>
import { parseTime } from '@/utils/index'
import { orderListTeam } from '@/api'
import QueryForm from '@/components/QueryForm'
export default {
  name: 'GroupRecord',
  components: {
    QueryForm
  },
  data() {
    return {
      queryFormConfig: {
        formItems: [{
          filed: 'name',
          type: 'input',
          label: this.$t('message.ttmc'),
          clearable: true
        }, {
          filed: 'type',
          type: 'select',
          label: this.$t('message.qylx'),
          clearable: true,
          options: [
            { value: '1', label: this.$t('message.shouchon') },
            { value: '2', label: this.$t('message.xuqian') }
          ]
        }, {
          filed: 'status',
          type: 'select',
          label: this.$t('message.jyzt'),
          clearable: true,
          options: [
            { value: '0', label: this.$t('message.dzf') },
            { value: '1', label: this.$t('message.zc') },
            { value: '2', label: this.$t('message.chexiao') }
          ]
        }],
        online: true
      },
      meta: [],
      list: [],
      totalCount: 0,
      filters: {},
      listLoading: true,
      show: false,
      pagination: {
        page: 1,
        rows: 10
      },
      orderId: '',
      form: {},
      rules: {
        price: [
          {
            pattern: /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/,
            required: true,
            message: this.$t('message.qsrzrksdj'),
            trigger: 'blur'
          }
        ],
        info: [
          {
            required: true,
            message: this.$t('message.fyyxxtk'),
            trigger: 'blue'
          }
        ]
      }
    }
  },
  created() {
    this.meta = this.$route.meta.buttons || []
    this.getList(1)
  },
  activated() {
    this.$refs.table.doLayout()
  },
  methods: {
    downLoadHt(hturl) {
      if (!hturl) {
        this.$message.warning(this.$t('message.zwht'))
        return
      }
      window.open(hturl, '_blank')
    },
    handleSizeChange(value) {
      this.pagination.rows = value
      this.getList(1)
    },
    // 获取续签记录列表
    getList(page) {
      this.listLoading = true
      const { filters, pagination } = this
      const venueId = sessionStorage.getItem('venueId')
      if (page) {
        pagination.page = page
        this.pagination.page = page
      }
      if (pagination.page === 1) {
        pagination.firstQueryTime = parseTime(new Date())
      }
      orderListTeam({
        pagination,
        param: {
          venueId,
          ...filters
        },
        userId: sessionStorage.getItem('userId')
      })
        .then((res) => {
          this.listLoading = false
          if (res.errorCode === '000000') {
            this.list = res.recordList
            this.totalCount = res.totalCount
          }
        })
        .catch((err) => {
          this.listLoading = false
          console.log(err)
        })
    },
    clear() {
      this.filters = {}
      this.getList(1)
    }
  }
}
</script>
